'''
实验名称：RGB彩灯控制
版本：v1.0
日期：2019.8
作者：01Studio 【www.01Studio.org】
说明：通过编程实现灯带不同颜色的变化。
'''
import time
from machine import Pin,Timer
from neopixel import NeoPixel

#定义红、绿、蓝三种颜色
RED=(25,0,0)
GREEN=(0,25,0)
BLUE=(0,0,25)
BLACK = (0,0,0)
global num
num = 8

#22引脚连接灯带，灯珠数量30
pin = Pin(5, Pin.OUT)
np = NeoPixel(pin, 25)

#设置灯珠颜色，本实验供30个灯珠
def Color_buf(color):
    for i in range(25):
        np[i]=color

def led(color):
    for i in range(0,10):
        np[num + i] = color
        np.write()
        np[num - i] = color
        np.write()
        np[num + i + 1] = color
        np.write()
        np[num - i - 1] = color
        np.write()
        np[num + i + 2] = color
        np.write()
        np[num - i - 2] = color
        np.write()
        np[num + i + 3] = color
        np.write()
        np[num - i - 3] = color
        np.write()        
        np[num + i] = BLACK
        np.write()        
        np[num - i] = BLACK
        np.write()
        time.sleep(0.2)

while True:
    led(GREEN)
    